lang: no need for pointer.Of in Go 1.26#27875
Open
pkazmierczak wants to merge 3 commits intomainfrom
Open
Conversation
pointer.Of in Go 1.26
Member
|
LGTM! I'll happily approve after mergeflicts are resolved. Because the changeset is so big, I did not look at every line with my eyeballs. Here is how I checked that the contents I got a bit carried away with Pythonbut for posterity, here's what I ran: #!/usr/bin/env python3
import re
import subprocess
class change:
def __init__(self, file, new, ptr, before, after):
self.file = file # filename
self.new = new # new()
self.ptr = ptr # pointer.Of()
# lines before and after for context
self.before = before
self.after = after
def is_copacetic(self):
# simple cases where type is inferred
# pointer.Of(val) => new(val)
if self.new == self.ptr.replace("-pointer.Of", "+new"):
return True
# within the pointer package
# Of(val) => new(val)
if self.file.startswith("helper/pointer") \
and self.new == self.ptr.replace("-Of(", "+new("):
return True
# getting a bit silly now, detect when the type is specified
# pointer.Of[type](val) => new(type(val))
groups = re.match(r"-pointer.Of\[(?P<type>[\d\w\.]+)\]\((?P<val>.*)\)", self.ptr)
if groups:
type = groups.group("type")
val = groups.group("val")
# strip occasional type redundancy
# pointer.Of[type](type(val)) => pointer.Of[type](val)
val = val.lstrip(f"{type}(").rstrip(")")
expect = f"+new({type}({val})"
# little variations on the suffix
if self.new == expect \
or self.new == expect + ")" \
or self.new == expect + "),":
return True
return False
def __repr__(self):
return f'{self.file=} {self.new=} {self.ptr=}'
def __str__(self):
return f"""\
>>> {self.file}
{self.before}
>>> {self.ptr}
>>> {self.new}
{self.after}"""
if __name__ == '__main__':
lines = subprocess.check_output(
# at the time of this script, HEAD~3 is just before these changes.
["git", "diff", "HEAD~3", "HEAD", "--word-diff=porcelain"]
).decode("utf-8").splitlines()
# clean up "~"-only lines
lines = [l for l in lines if l != '~']
# collect changes
changes = []
file = None
for i, line in enumerate(lines):
if line.startswith('---'):
file = line.split('--- a/')[1]
if line.startswith("+new("):
# each +new should have a -pointer.Of right before it,
# so we have everything we need from here.
changes.append(change(
file=file,
new=line,
ptr=lines[i-1],
# lines before and after for context
before="\n".join(lines[i-3:i-1]),
after="\n".join(lines[i+1:i+4]),
))
for ch in changes:
if not ch.is_copacetic():
print(ch)
print(f"\nHOW MANY: {len(changes)}")Result: found lots of changes, and the one outlier looks copacetic to me. Do you intend to backport this, dear friend? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.